package com.linx.park.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.linx.common.core.domain.R;
import com.linx.common.core.validate.AddGroup;
import com.linx.common.core.validate.EditGroup;
import com.linx.common.excel.utils.ExcelUtil;
import com.linx.common.idempotent.annotation.RepeatSubmit;
import com.linx.common.log.annotation.Log;
import com.linx.common.log.enums.BusinessType;
import com.linx.common.mybatis.core.page.PageQuery;
import com.linx.common.mybatis.core.page.TableDataInfo;
import com.linx.common.web.core.BaseController;
import com.linx.park.domain.bo.ParkPlaceBo;
import com.linx.park.domain.vo.ParkPlaceVo;
import com.linx.park.service.IParkBuildingAreaService;
import com.linx.park.service.IParkBuildingFloorService;
import com.linx.park.service.IParkPlaceService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 园区楼栋区域
 *
 * @author 泽智科技
 * @date 2024-10-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/park/park-building-area")
public class ParkBuildingAreaController extends BaseController {

    private final IParkBuildingAreaService parkBuildingAreaService;

    /**
     * 查询园区楼栋列表
     */
    @SaCheckPermission("park:park-building-area:list")
    @GetMapping("/list")
    public TableDataInfo<ParkPlaceVo> list(ParkPlaceBo bo, PageQuery pageQuery) {
        return parkBuildingAreaService.queryPageList(bo, pageQuery);
    }
    /**
     * 新增园区区域
     */
    @SaCheckPermission("park:park-building-area:add")
    @Log(title = "园区区域", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ParkPlaceBo bo) {
        return toAjax(parkBuildingAreaService.insertByBo(bo));
    }

    /**
     * 获取园区区域详细信息
     *
     * @param parkPlaceId 主键
     */
    @SaCheckPermission("park:park-building-area:query")
    @GetMapping("/{parkPlaceId}")
    public R<ParkPlaceVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long parkPlaceId) {
        return R.ok(parkBuildingAreaService.queryById(parkPlaceId));
    }
    /**
     * 修改园区区域
     */
    @SaCheckPermission("park:park-building-area:edit")
    @Log(title = "园区区域", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ParkPlaceBo bo) {
        return toAjax(parkBuildingAreaService.updateByBo(bo));
    }
    /**
     * 删除园区区域
     *
     * @param parkPlaceIds 主键串
     */
    @SaCheckPermission("park:park-building-area:remove")
    @Log(title = "园区区域", businessType = BusinessType.DELETE)
    @DeleteMapping("/{parkPlaceIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] parkPlaceIds) {
        return toAjax(parkBuildingAreaService.deleteWithValidByIds(List.of(parkPlaceIds), true));
    }
}
